<template>
    <el-row class="edit">
        <el-container style="height: 100%;">
            <el-header height="60px">
                新增参数
            </el-header>
            <el-main>
                <el-form ref="addFstParaData" :rules="rules" :model="addFstParaData" label-width="115px"
                         label-position="left">
                    <el-form-item label="参数名称 :" prop="name">
                        <el-input v-model="addFstParaData.name" placeholder="请输入参数名称"></el-input>
                    </el-form-item>
                    <el-form-item label="参数代码 :" prop="code">
                        <el-input v-model="addFstParaData.code" placeholder="请输入参数代码"></el-input>
                    </el-form-item>
                    <el-form-item label="参数值 :" prop="val">
                        <el-input v-model="addFstParaData.val" placeholder="请输入参数值"></el-input>
                    </el-form-item>
                </el-form>
            </el-main>
            <el-footer height="80px">
                <el-row style="height: 20px;margin-bottom: 5px;">
                    <transition name="el-zoom-in-bottom">
                        <el-row v-show="infoShow" style="display: flex;justify-content: center;align-items: center;">
                            {{ (info !== '') ? "提示信息："+info : ''}}
                        </el-row>
                    </transition>
                </el-row>

                <el-row style="display: flex;justify-content: center;align-items: center;">
                    <el-button @click="submit" type="primary">
                        完成新增
                    </el-button>
                    <el-button @click="editOut">
                        取消新增
                    </el-button>
                </el-row>
            </el-footer>
        </el-container>
    </el-row>
</template>

<script>
    import {replaceSpacesObj} from '../../../utils/webUtils.js';

    export default {
        name: "addFirstPara",
        data() {
            return {
                formAlignLeft: 'left',
                addFstParaData: {
                    name: '',
                    code: '',
                    val: '',
                    patUuid: '',
                    patName: '',
                    patCode: ''
                },
                rules: {
                    name: [
                        {required: true, message: '参数名称不得为空', trigger: 'blur'},
                    ],
                    code: [
                        {required: true, message: '参数代码不得为空', trigger: 'blur'},
                    ],
                    val: [
                        {required: true, message: '参数值不得为空', trigger: 'blur'},
                    ]
                },
                info: '',
                infoShow: false
            }
        },
        mounted() {
        },
        methods: {
            submit() {
                this.$refs['addFstParaData'].validate((valid) => {
                    if (!valid) {
                        return;
                    }
                    this.axios.request({
                        method: "post",
                        url: "./kwp/kdi/para",
                        headers: {
                            "Content-Type": "application/json;charset=UTF-8"
                        },
                        data: replaceSpacesObj(this.addFstParaData)
                    }).then(response => {
                        this.info = '新增成功,两秒后关闭';
                        this.infoShow = true;
                        setTimeout(() => {
                            this.infoShow = false;
                            this.$emit("editState", false);
                            this.cleanPara();
                            this.info = '';
                        }, 2000);
                    }).catch(error => {
                        console.log(error);
                        this.info = '新增失败';
                        this.infoShow = true;
                    });
                });

            },
            editOut() {
                this.infoShow = false;
                this.cleanPara();
                this.info = '';
                this.$emit("editState", false);
            },
            cleanPara() {
                this.addFstParaData = {
                    name: '',
                    url: '',
                    alias: '',
                    ico: '',
                    inx: '',
                    patUuid: '',
                    patName: '',
                    enabled: '',
                    visible: ''
                };
            }
        }
    }
</script>

<style scoped>
    .edit {
        width: 334px;
        height: 100%;
        z-index: 100;
    }


</style>